<? 
    session_start();
	include_once ("core/conn.php");
	$db = get_conn();
	check_session();
	//get_header();
	$id = $_GET['id'];
	if($id != ''){
		$sql = " select * from rol where id_rol='".$id."'"; 
		$result = mysql_query($sql);	
		if($result){
			$row = mysql_fetch_array($result);
			 $id_rol = $row['id_rol'];
			 $name = $row['name'];

		}else{
			
			error_handling(__FUNCTION__.$sql,mysql_error());
		}
	}
	
	
?>
<html>
<head>
<link href="css/admin_styles.css" rel="stylesheet" type="text/css" />

<script>
	function check_rol(obj){
							
		if(obj.name.value ==''){
								
			alert('Please fill the name');
								
			obj.name.focus();
								
			return false;
							
		}
		
		return true;		
	}
</script>
</head>
<body>
<form name='rol' method='post' action='/core/rol.php' onsubmit='return check_rol(this)'>
  <table border='0' width="100%" align="center">
    <tr>
      <td colspan="2" valign="top"><div align="center">
          <h2>Roles</h2>
        </div></td>
    </tr>
    <tr>
      <td colspan="2" valign="top"><div class="tabber">
          <div class="tabbertab">
            <h2>Crear / Editar</h2>
            <table width="98%"   border='0' class="table_border">
              <input type='hidden' name='id_rol' value='<? echo $id_rol;?>' />
              <tr>
                <td width="17%" class="etiqueta_form2">Rol Name</td>
                <td width="83%"><input type='text' class="contenido_forma" name='name' value='<? echo $name;?>' /></td>
              </tr>
              <tr>
                <td colspan="2" align='center' class="texto"><div align="left">Select to give access for</div></td>
              </tr>
              <tr>
                <td align='center' class="texto"><div align="left"></div></td>
                <td align='left'><? echo get_modules(1,$id)?></td>
              </tr>
              <tr>
                <td colspan='2' align='center'><?
					  if ($id != ""){
						echo "<input type='submit' name='Actualizar' value='Update'>";
						echo "&nbsp;&nbsp;<input type='submit' name='Eliminar' value='Delete'>";										
						echo "&nbsp;&nbsp;<input type='submit' name='Nuevo' value='New'>";
					  }else{
						echo "<input type='submit' name='Agregar' value='Add'>";
					  }
					?>
                </td>
              </tr>
            </table>
          </div>
          <div class="tabbertab">
            <h2>Existentes</h2>
            
            <? $sql = "select id_rol as id,name as description from rol ";
			$result = mysql_query($sql);
			if($result){
				$data ="<table  width='100%' border='0' >";
				if(mysql_num_rows($result) > 0){
					while($row = mysql_fetch_array($result)){
						$data .= 
						"<tr>
							<td align='left' width='50%'>
								<a class='ac_vinculo2'  href='rol.php?id=".$row['id']."'>".$row['description']."</a>
							</td>
	
						</tr>";
					}//while
				}//if
				else{
					$data .= "<tr><td align='center'>No Rol Registered</td></tr>";			
				}
				$data .="</table>";
			}else{
				
				error_handling(__FUNCTION__.$sql,mysql_error());
			}
			echo $data;
			?>
           </div>
        </div></td>
    </tr>
    <tr>
      <td width="377"></td>
    </tr>
  </table>
</form>
</body>
</html>
<?



function get_columns_checks($id_rol){
	if($id_rol !=''){
		$sql ="select * from rol_column where id_rol=".$id_rol;
		//echo $sql;
		$result = mysql_query($sql);
		if($result){
			while($row = mysql_fetch_array($result)){
				$col.=$row['id_column'].",";
			}
			$col= substr($col,0,(strlen($col)-1));
		}else{
			error_handling("get_columns_checks: ".$sql,mysql_error());
		}
	}

	$sql ="select * from securitycolumn order by detalle";
	$result = mysql_query($sql);
	if($result){
		while($row = mysql_fetch_array($result)){
			$data.="<tr>";
			$data.="<td><input type='checkbox' name='id_col[]' value='".$row['id']."' ".is_in_list($col,$row['id']).">".$row['detalle']."</td>";
			$data.="</tr>";
		}//while
		return "<table border='0' class='contenido_forma'>".$data."</table>";
	}else{
		
		error_handling("get_columns_checks: ".$sql,mysql_error());
	}

}	

	//get_foother();
	
?>
